package shape;
import java.util.Random;

abstract class Shape {
    // 抽象方法：计算面积
    public abstract double calculateArea();
}

class Circle extends Shape {
    private double radius;

    // 构造方法
    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double calculateArea() {
        return Math.PI * radius * radius;
    }
}

class Rectangle extends Shape {
    private double length;
    private double width;

    // 构造方法
    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double calculateArea() {
        return length * width;
    }
}

public class xz {
    public static void main(String[] args) {
        // 创建形状数组，包含不同类型的Shape
        Shape[] shapes = new Shape[10];  // 假设数组大小为10
        Random random = new Random();

        // 随机添加Circle和Rectangle对象
        for (int i = 0; i < shapes.length; i++) {
            if (random.nextBoolean()) {
                // 随机创建Circle对象
                double radius = random.nextInt(10) + 1;  // 半径1到10
                shapes[i] = new Circle(radius);
            } else {
                // 随机创建Rectangle对象
                double length = random.nextInt(10) + 1;  // 长度1到10
                double width = random.nextInt(10) + 1;   // 宽度1到10
                shapes[i] = new Rectangle(length, width);
            }
        }

        // 计算并输出每个形状的面积
        for (int i = 0; i < shapes.length; i++) {
            System.out.println("Shape " + (i + 1) + " Area: " + shapes[i].calculateArea());
        }
    }
}
